package com.lmq.wxshare.controller;

import com.lmq.wxshare.common.ListCommon;
import com.lmq.wxshare.constants.WxConstants;
import com.lmq.wxshare.entity.Produce;
import com.lmq.wxshare.service.ProduceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/index")
public class IndexController extends BaseController{

    @Autowired
    private ProduceService produceService;
    @Autowired
    private WxConstants wxConstants;

    static String REDIRECT_URI = "http%3a%2f%2f127.0.0.1%3a8080%2fwx%2fgetAccessTokenByCode";

    /*商品列表*/
    @RequestMapping("/produces")
    public String index(Model model){
        /*授权地址*/
        String authorizeUrl = wxConstants.getAuthorizeUrl().replace("APPID",wxConstants.getAppID()).replace("REDIRECT_URI",REDIRECT_URI).replace("SCOPE","snsapi_userinfo");
        List<Produce> list = produceService.list(null);
        list = ListCommon.resetProduces(list, authorizeUrl);
        model.addAttribute("produces",list);
        return "index/produces";
    }

}
